package com.wyx.suanfa;

/**
 * @author 王艺锡
 * @version 1.0
 */
public class mergeKLists {
    //给你一个链表数组，每个链表都已经按升序排列。
    //
    //请你将所有链表合并到一个升序链表中，返回合并后的链表。
    public static void main(String[] args) {


    }
}
/*
* /**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }

class Solution {
    public ListNode mergeKLists(ListNode[] lists) {
        ListNode ret = null;
        for(int i = 0;i<lists.length;i++){
            ret = connectList(ret,lists[i]);
        }
        return ret;
    }

    private ListNode connectList(ListNode a,ListNode b){
        if(a == null || b == null){
            return a == null? b : a;
        }
        ListNode ret = new ListNode();
        ListNode temp = ret;
        ListNode aCur = a;
        ListNode bCur = b;
        while(aCur != null && bCur != null){
            if(aCur.val <= bCur.val){
                temp.next = aCur;
                aCur = aCur.next;
            }else {
                temp.next = bCur;
                bCur = bCur.next;
            }
            temp = temp.next;
        }
        temp.next = aCur == null? bCur : aCur;
        return ret.next;
    }
}*/